var booking = new Vue({
    el:'#booking',
    data:{
        perpay:'',
        sum:'',
        pay:'',
        frist: {
            guestName:'',
            sex:'男',
            identity:'',
            tel:'',
            beginDay:'',
            perDay:'',
            roomNum:'',
        },
        companionList:[]
    },
    methods:{
        addGuest:function(){
            this.companionList.push({
                guestName:'',
                sex:'男',
                identity:'',
                tel:''
            });
        },
        deleteGuest:function(){
            if(this.companionList.length>0){
                this.companionList.pop();
            } 
        },
        select:function(){
            this.perpay = '';
            this.sum = '';
            $.ajax({
                url:'selectMoney',
                type:'POST',
                cache:false,
                dataType:'json',
                data:{
                    roomNum : this.frist.roomNum,
                    perDay : this.frist.perDay
                },
                success:function(data){
                    if(data.status == "error"){
                        alert(data.info);
                        return;
                    }
                    booking.perpay = data.info[0];
                    booking.sum = data.info[1];
                },
                error:function(){
                    alert("请刷新网络")
                }
            })
        },
        submitInformation:function(){
            var data ={};
            data["pay"] = this.pay;
            data["frist"] = this.frist;
            data["companionList"] = this.companionList;
            var jsonString = JSON.stringify(data);
            $.ajax({
                url:'submitInformation',
                type:'POST',
                cache:false,
                dataType:'json',
                data: {
                    jsonString : jsonString
                },
                success:function(data){
                    alert(data.info);
                },
                error:function(data){
                    alert(data.info);
                }
            })
        }
    }
});